(function() {
    angular.module('app').component('jqPopupModal', {
        templateUrl: 'app/directives/jq.popup/jq.popup.modal/jq.popup.modal.html',
        controller: jqPopupModal,
        controllerAs: 'vm'
    });

    jqPopupModal.$inject = ['$rootScope', '$scope'];

    function jqPopupModal($rootScope, $scope) {
        $('#jq-modal-box').modal();

        var clearFun = $rootScope.$on('JQ_MODAL_EV', function(e, callback) {
            $('#jq-modal-box').modal('open');
            callback();
        });

        $scope.$on('$destroy', function() {
            clearFun();
        });
    }
})();
